#include "Tilemap.h"
#include "Level.h"

#include "Point.h"

#include "Character.h"

bool Character::step(Direction dir) {
	int totalAction = 1;
	
	if (m_condition & BURDENED)
		totalAction = 2;
	if (m_condition & STRAINED)
		totalAction = 3;
	if (m_condition & STARVING)
		totalAction++;
	
	Tilemap* tilemap = m_gameLevel->tilemap();
	
	Point temp = m_coord;
	if (dir == NORTH)		m_coord.y--;
	if (dir == WEST)		m_coord.x--;
	if (dir == EAST)		m_coord.x++;
	if (dir == SOUTH)		m_coord.y++;
	if (dir == NORTH_WEST)	{ m_coord.y--; m_coord.x--; }
	if (dir == NORTH_EAST)	{ m_coord.y--; m_coord.x++; }
	if (dir == SOUTH_EAST)  { m_coord.y++; m_coord.x++; }
	if (dir == SOUTH_WEST)  { m_coord.y++; m_coord.x--; }
	
	if (tilemap->passable(coord().x, coord().y)) {
		
		// Even if we exceed the action points, we
		// still allow the character to move a single
		// step.
		
		m_actionPoints -= totalAction;
		if (m_actionPoints < 0) m_actionPoints = 0;
	} else {
		m_coord = temp;
		return false;
	}

	return true;
}

void Character::attack(Character* character) {
}

bool Character::pickup(Item* item) {
	int totalWeight = item->weight() + m_inventory.totalWeight();
	if (totalWeight > carryingCapacity())
		return false;
	
	// Inventory can be full.
	bool success = m_inventory.add(item);
	if (success) {
		m_actionPoints--;
	
		return true;
	}
	return false;
}


